<?php

use yii\db\Migration;

class m171129_023538_create_price_package extends Migration
{
    private function createDbs(){
        $dbs = [];
        $dbs_info =\Yii::$app->params['db'];
        foreach($dbs_info as $k=>$v){
            $dbs[$k] = \Yii::createObject($v);
        }
        return $dbs;
    }

    public function safeUp()
    {
        $dbs = $this->createDbs();
        foreach ($dbs as $v) {
            $this->db = $v;
            $this->createTable('{{%price_package}}',[
                'id' => $this->primaryKey()->notNull().' COMMENT \'自增id\'',
                'price_name' => $this->string(50)->defaultValue(null)->comment('价格套餐名称'),
                'lesson' => $this->smallInteger()->defaultValue(0)->comment('课次'),
                'discount' => $this->smallInteger()->defaultValue(100)->comment('折扣率'),
                'distribution_way' => $this->smallInteger(1)->defaultValue(0)->comment('分成方式 0 固定分成 1 比例分成'),
                'subsidy_type' => $this->smallInteger(1)->defaultValue(0)->comment('课时补贴方式（1，按学生 2 课程）'),
                'type_id' => $this->smallInteger(2)->defaultValue(0)->comment('三大类id （1 益智  2 音乐  3  形体）'),
                'cate_id' => $this->integer()->defaultValue(0)->comment('分类id'),
                'is_scholarship' => $this->smallInteger(1)->defaultValue(2)->comment('是否支持奖学金 1 是 2 否'),
                'is_activity' => $this->smallInteger(1)->defaultValue(0)->comment('是否时活动 0 否 1是'),
                'activity_name' => $this->string(100)->defaultValue(null)->comment('活动名称'),
                'activity_start_time' => $this->integer()->defaultValue(0)->comment('活动开始时间'),
                'activity_end_time' => $this->integer()->defaultValue(0)->comment('活动结束时间'),
                'effective_number' => $this->smallInteger()->defaultValue(0)->comment('活动有效人数'),
                'is_frequency' => $this->smallInteger(1)->defaultValue(1)->comment('是否限制上课次数 0 否 1 是'),
                'deadline_type' => $this->string(10)->defaultValue(null)->comment('不限上课次数限制类型 （month月/year年）'),
                'deadline' => $this->smallInteger(4)->defaultValue(0)->comment('有效期 例如 1 个月 1 年'),
                'status' => $this->smallInteger(1)->defaultValue(1)->comment('1 启用 2 禁用'),
                'updated_at' => $this->integer(11)->defaultValue(0)->comment('创建时间'),
                'created_at' => $this->integer(11)->defaultValue(0)->comment('创建时间')
            ]);
        }
    }

    public function safeDown()
    {
        $dbs = $this->createDbs();
        foreach ($dbs as $v) {
            $this->db = $v;
            $this->dropTable('{{%channel_distribution}}');
        }
    }
}
